//
//  SX-StartView.m
//  ShiXun
//
//  Created by lanou on 15/11/5.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SX-StartView.h"

@interface SX_StartView () <UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation SX_StartView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        _scrollView.pagingEnabled = YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.delegate = self;
        _scrollView.bounces = NO;
        _scrollView.contentSize = CGSizeMake(kScreenWidth * 4, kScreenHeight);
        [self addSubview:_scrollView];
        
        for (int i = 0; i < 4; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight)];
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"SX-qidong%d", i]];
            if (i == 3) {
                imageView.userInteractionEnabled = YES;
                _goinButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
                _goinButton.frame = CGRectMake(0, kScreenHeight * 3 / 4 - 40, kScreenWidth, 50);
                [imageView addSubview:_goinButton];
            }
            [_scrollView addSubview:imageView];
        }
        
        _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, kScreenHeight - 50, kScreenWidth, 30)];
        _pageControl.numberOfPages = 4;
        [self addSubview:_pageControl];
    }
    return self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger page = (scrollView.contentOffset.x + scrollView.bounds.size.width / 2) / scrollView.bounds.size.width;
    self.pageControl.currentPage = page;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
